﻿using NUnit.Framework;
using AdventureWorks.DataAccess.repository;
using AdventureWorks.DataAccess.SearchCriterias;
using System.Linq;
using AdventureWorks.DataAccess.Test.repository;
using AdventureWorks.DataAccess.Task;

namespace AdventureWorks.DataAccess.Test.task
{
    [TestFixture]
    public class PagingTest : RepositoryTestBase<VendorRepository>
    {

        [Test]
        public void Should_set_default_page_size_to_10()
        {
            var criteria = new VendorSearchCriteria();
            Assert.AreEqual(10, criteria.PageSize);
        }


        [Test]
        public void Should_set_default_page_to_1()
        {
            var criteria = new VendorSearchCriteria();
            Assert.AreEqual(1, criteria.Page);
        }

        [Test]
        public void Should_get_only_the_page_size()
        {
            var criteria = new VendorSearchCriteria();
            var vendors = repository.GetVendors(session, criteria);
            Assert.AreEqual(104, vendors.Count());
            var list = vendors.Paging(criteria).ToList();
            Assert.AreEqual(10, list.Count);
            Assert.AreEqual("AUSTRALI0001", list[0].AccountNumber);
        }

        [Test]
        public void Should_get_the_proper_page_when_set_the_page()
        {
            var criteria = new VendorSearchCriteria() { Page = 3 };
            var vendors = repository.GetVendors(session, criteria).Paging(criteria);
            var list = vendors.ToList();
            Assert.AreEqual("KNOPFLER0001", list[0].AccountNumber);
        }

        [Test]
        public void Should_get_the_proper_page_size_when_set_the_pagesize()
        {
            var criteria = new VendorSearchCriteria() { Page = 2, PageSize = 20 };
            var vendors = repository.GetVendors(session, criteria).Paging(criteria);
            var list = vendors.ToList();
            Assert.AreEqual(20, list.Count);
            Assert.AreEqual("KNOPFLER0001", list[0].AccountNumber);
        }
    }
}
